package nl.hu.verbrandendephoenix.view;

import java.util.ArrayList;

import nl.hu.verbrandendephoenix.shared.Auction;
import nl.hu.verbrandendephoenix.shared.Bid;
import nl.hu.verbrandendephoenix.shared.User;

import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Grid;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.ListBox;
import com.google.gwt.user.client.ui.Panel;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.VerticalPanel;

public class ViewAuction {

	private Panel pnlViewAuction;
	public Grid grdViewAuction, grdButtons;
	public Label lblAuctionName, lblDescription, lblPrice, lblCategory, lblOwner, lblCurrentOffer, lblOfferBy, lblOfferDate, lblOffer, lblStartDate, lblEndDate, lblOwnerID, lblWinner;
	private TextBox txtOffer;
	public TextBox txtDescription;
	public ListBox category;
	private Button btnBid, btnCancel, btnRemove;
	public Button btnEdit, btnClose, btnSave, btnStats, btnSale;

	public ViewAuction() {
		pnlViewAuction = new VerticalPanel();
		pnlViewAuction.addStyleName("post");
	}

	public Panel constructForm() {
		grdViewAuction = new Grid(7,3);
		grdButtons = new Grid(2, 7);

		lblAuctionName = new Label();
		lblDescription = new Label();
		lblPrice = new Label();
		lblCategory = new Label();
		lblOwner = new Label();
		lblCurrentOffer = new Label();
		lblOfferBy = new Label();
		lblOfferDate = new Label();
		lblOffer = new Label("Bieding: ");
		lblStartDate = new Label();
		lblEndDate = new Label();
		lblWinner = new Label("Het winnende bod: ");

		txtOffer = new TextBox();
		txtOffer.setSize("35px", "20px");
		txtDescription = new TextBox();

		category = new ListBox();

		btnBid = new Button("Bied");
		btnCancel = new Button("Annuleren");
		btnEdit = new Button("Wijzig veiling");
		btnClose = new Button("Sluit veiling");
		btnSave = new Button ("Sla op");
		btnStats = new Button("Statistieken");
		btnSale = new Button("Verkoop");
		btnRemove = new Button("Verwijder veiling");

		btnEdit.setVisible(false);
		btnClose.setVisible(false);
		btnSave.setVisible(false);
		btnStats.setVisible(false);
		btnSale.setVisible(false);

		grdButtons.setWidget(0, 0, lblOffer);
		grdButtons.setWidget(0, 1, txtOffer);
		grdButtons.setWidget(1, 0, btnBid);
		grdButtons.setWidget(1, 1, btnCancel);
		grdButtons.setWidget(1, 2, btnEdit);
		grdButtons.setWidget(1, 4, btnClose);
		grdButtons.setWidget(1, 5, btnStats);
		grdButtons.setWidget(1, 6, btnSale);

		pnlViewAuction.add(grdViewAuction);
		pnlViewAuction.add(grdButtons);

		return pnlViewAuction;
	}
	
	public void closedAuction(User u, Bid b, Auction a) {
		Panel pnlClosedAuction = new VerticalPanel();
		Grid grdClosedAuction = new Grid(7,1);
		
		grdClosedAuction.setWidget(0, 0, new Label("Veiling " + a.getAuctionName() + " is verkocht aan " + u.getFirstName() + " " + u.getLastName() + " voor " + b.getPrice() + " credits."));
		grdClosedAuction.setWidget(1, 0, new Label());
		grdClosedAuction.setWidget(2, 0, new HTML("<B>Adresgegevens</B>"));
		grdClosedAuction.setWidget(3, 0, new Label(u.getFirstName() + " " + u.getLastName()));
		grdClosedAuction.setWidget(4, 0, new Label(u.getStreet() + " " + u.getStreetNumber()));
		grdClosedAuction.setWidget(5, 0, new Label(u.getZIPCode() + ", " + u.getCity()));
		
		grdClosedAuction.setWidget(6, 0, btnRemove);
		
		pnlClosedAuction.add(grdClosedAuction);
		
		RootPanel.get("content").clear();
		RootPanel.get("content").add(pnlClosedAuction);
	}

	public ArrayList<TextBox> getArrTextBox() {
		ArrayList<TextBox> arrTextBox = new ArrayList<TextBox>();
		arrTextBox.add(txtOffer);
		return arrTextBox;
	}

	public Panel getPnlViewAuction() {
		return pnlViewAuction;
	}
	
	public Label getLblAuctionName() {
		return lblAuctionName;
	}
	
	public void setLblAuctionName(Label lblAuctionName) {
		grdViewAuction.setWidget(0, 0, lblAuctionName);
		lblAuctionName.addStyleName("h1");
	}

	public Label getLblDescription() {
		return lblDescription;
	}

	public void setLblDescription(Label lblDescription) {
		grdViewAuction.setWidget(1, 0, lblDescription);
	}

	public TextBox gettxtDescription(){
		return txtDescription;
	}

	public void settxtDescription(TextBox txtDescription){
		txtDescription.setEnabled(false);
		txtDescription.setVisible(false);
	}

	public Label getLblPrice() {
		return lblPrice;
	}

	public void setLblPrice(Label lblPrice) {
		grdViewAuction.setWidget(2, 0, lblPrice);
	}

	public Label getLblCategory() {
		return lblCategory;
	}

	public void setLblCategory(Label lblCategory) {
		grdViewAuction.setWidget(3, 0, lblCategory);
	}

	public void setcategory(ListBox category){
		category.setVisible(false);
		category.setEnabled(false);
	}

	public Label getLblOwner() {
		return lblOwner;
	}

	public void setLblOwner(Label lblOwner) {
		grdViewAuction.setWidget(4, 0, new Label("Aanbieder: " + lblOwner.getText()));
		setLblOwnerID(lblOwner);
	}

	public Label getLblCurrentOffer() {
		return lblCurrentOffer;
	}

	public void setLblCurrentOffer(Label lblCurrentOffer) {
		grdViewAuction.setWidget(2, 1, lblCurrentOffer);
	}

	public Label getLblStartDate() {
		return lblStartDate;
	}

	public void setLblStartDate(Label lblStartDate) {
		grdViewAuction.setWidget(5, 0, lblStartDate);
	}

	public Label getLblEndDate() {
		return lblEndDate;
	}

	public void setLblEndDate(Label lblEndDate) {
		grdViewAuction.setWidget(5, 1, lblEndDate);
	}

	public TextBox getTxtOffer() {
		return txtOffer;
	}

	public void setTxtOffer(String text) {
		txtOffer.setText(text);
	}

	public Button getBtnBid() {
		return btnBid;
	}

	public Button getBtnCancel() {
		return btnCancel;
	}

	public Button getBtnEdit(){
		return btnEdit;
	}

	public Button getBtnClose(){
		return btnClose;
	}

	public Button getBtnSave(){
		return btnSave;
	}
	
	public Button getBtnRemove(){
		return btnRemove;
	}

	public Label getLblOfferBy() {
		return lblOfferBy;
	}

	public void setLblOfferBy(Label lblOfferBy) {
		grdViewAuction.setWidget(3, 1, lblOfferBy);
	}

	public Label getLblOfferDate() {
		return lblOfferDate;
	}

	public void setLblOfferDate(Label lblOfferDate) {
		grdViewAuction.setWidget(4, 1, lblOfferDate);
	}

	public Label getLblOwnerID() {
		return lblOwnerID;
	}

	public void setLblOwnerID(Label lblOwnerID) {
		this.lblOwnerID = lblOwnerID;
	}
	
	public Label getLblWinner(){
		return lblWinner;
	}
	
	public void setLblWinner(Label lblWinner){
		this.lblWinner = lblWinner;
	}
	
	public Button getBtnStats() {
		return btnStats;
	}
	
	public void setBtnStats(Button btn) {
		btnStats = btn;
	}
	
	public void setBtnRemove(Button btn) {
		btnRemove = btn;
	}
	
	public Button getBtnSale(){
		return btnSale;
	}
	
	public void setBtnSale(Button btn){
		btnSale = btn;
	}
}
